import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from './pipe/validatePipe';
import { ConditionalInterceptor } from './Interceptor';
import { Reflector } from '@nestjs/core';
import { JwtService } from '@nestjs/jwt';
import { RedisService } from './database/redis';
import * as fs from 'fs';
import * as path from 'path';
async function bootstrap() {
  // const httpsOptions = {
  //   cert: fs.readFileSync(path.join(__dirname, './ar.pem')), // 替换为你实际的路径
  //   key: fs.readFileSync(path.join(__dirname, './ar.key')), // 替换为你实际的路径
  // };
  // const app = await NestFactory.create(AppModule,{
  //   httpsOptions
  // });
  const app = await NestFactory.create(AppModule);

  app.enableCors({
    origin: '*', // 允许的来源
    methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', // 允许的请求方法
    credentials: true, // 是否允许携带凭证
  });

  app.useGlobalPipes(new ValidationPipe());
  app.useGlobalInterceptors(
    new ConditionalInterceptor(
      app.get(Reflector),
      app.get(JwtService),
      app.get(RedisService),
    ),
  );
  await app.listen(3000);
}
bootstrap();
